package hzn.controller;

import hzn.entity.Dept;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import java.util.List;

@RestController
public class DeptController_Consumer {
    static String url="http://provider-dept";
    @Autowired
    RestTemplate tmp;
    @RequestMapping("/consumer/dept/add")
    public boolean add(Dept d){
        System.out.println("dept:"+d);
        return tmp.postForObject(url+"/dept/add",d,Boolean.class);
    }

    @RequestMapping("/consumer/dept/get/{id}")
    public Dept get(@PathVariable Integer id){
        System.out.println("id:"+id);
        return tmp.getForObject(url+"/dept/get/"+id,Dept.class);
    }

    @RequestMapping("/consumer/dept/list")
    public List<Dept> list(){
        return tmp.getForObject(url+"/dept/list",List.class);
    }


}
